// 注册
$("#goto-register").on("click", function () {
    $("#register").stop().show()
})
//已有账号登录
$("goto-register").on("click", function () {
    $("#register").stop().hide()
})
//基于layui验证插件--扩展自定义规则

//注册功能编写
$("#register .layui-form").on("submit", function (ev) {
    ev.preventDefault();
    var data = {
        username: $("#register input[name=username]").val(),
        password: md5($("#register input[name=password]").val())

    }
    var arr = [];
    for (var prop in data) {
        arr.push(`${prop}=${data[prop]}`);

    }
    var argStr = arr.join("&");
    console.log(argStr);
    registerAPI(argStr, res => console.log(res))


})
//登录功能的编写
$("#login .layui-form").on("submit", function (ev) {
    ev.preventDefault();
    var data = {
        username: $("#login input[name=username]").val(),
        password: md5($("#login input[name=password]").val())
    }
    var arr = [];
    for (var prop in data) {
        arr.push(`${prop}=${data[prop]}`);
    }
    var argStr = arr.join("&");
    loginAPI(argStr, res => {
        sessionStorage.setItem("token", res.data.token)
        window.location.href = './index.html'
    })
})
